var searchParams;
		$(function(){
			//添加按钮事件
			$('#addactivity').on('click', function() {
				var node=businessTable.datagrid('getSelected');
				if (node) {
					addactivity(node.BUSINESS_ID);
				} else {
					layer.msg('请选择一条商家！', {
						time : 1000
					})
				}
			});
			//修改按钮事件
			$('#editactivity').on('click', function() {
				var node = activityTable.datagrid('getSelected');
				if (node) {
					openedit(node.ACTIVITY_ID);
				} else {
					layer.msg('请选择一条数据！', {
						time : 1000
					})
				}
			});
			//启用
			$('#able').on('click', function() {
				var node = activityTable.datagrid('getSelected');
				if (node) {
					if(node.DISABLE!='否')
					able(node.BUSINESS_ID,node.ACTIVITY_ID);
					else {
						layer.msg('该活动已经启用！', {
							time : 1000
						})
					}
					
				} else {
					layer.msg('请选择一条数据！', {
						time : 1000
					})
				}
			});
			
			//禁用
			$('#enable').on('click', function() {
				var node = activityTable.datagrid('getSelected');
				if (node) {
					if(node.DISABLE!='是')
						enable(node.ACTIVITY_ID);
					else {
						layer.msg('该活动已经禁用！', {
							time : 1000
						})
					}
					
				} else {
					layer.msg('请选择一条数据！', {
						time : 1000
					})
				}
			});
			//删除按钮事件
			$('#del').on('click', function() {
				del();
			});
			//查询按钮事件
			$('#searchctivity').on('click', function() {
				opensearch();
			});
		});
		//Table表格数据源
		var activityTable = $('#activity_table').datagrid(BasicData.createDatagrid({  
			url : '',
			frozenColumns:[[
				{field:'ck',checkbox:true},
				{title:'ACTIVITY_ID',field:'ACTIVITY_ID',hidden:true}
			]],
			columns:[[
	            {field:'BUSINESS_ID',title:'商户ID',width:'10%',align:'center',hidden:true},
	            {field:'TITLE',title:'标题',width:'10%',align:'center'},
	            {field:'SCOPE',title:'适用范围',width:'10%',align:'center', 
	            	formatter : function(value, row, index) {
						if (value == "WX")
							return "微信";
						if (value == "ZFB")
							return  "支付宝";
						if (value == "WX,ZFB") 
							return  "微信,支付宝";
					}	
	            
	            },
	            
	            {field:'DESCRIBE',title:'描述',width:'10%',align:'center'},
				{field:'WEEK',title:'星期',width:'10%',align:'center'},
				{field:'START_DATE',title:'开始日期',width:'10%',align:'center'},
				{field:'END_DATE',title:'结束日期',width:'10%',align:'center'},
				{field:'START_TIME',title:'起始时间',width:'10%',align:'center'},
				{field:'END_TIME',title:'结束时间',width:'10%',align:'center'},
				{field:'DISABLE',title:'是否启用',width:'10%',align:'center', 
	            	formatter : function(value, row, index) {
						if (value == "是")
							return "否";
						if (value == "否")
							return  "是";
						
					}	},
				{field:'CREATEDATE',title:'创建时间',width:'10%',align:'center'}
			]],
			onDblClickRow:function(rowIndex, rowData){
				
			}
		}));  
		//打开查询窗体
		function opensearch(){
			parent.layer.open({
				title : '查询条件',
				type : 2,
				btn : ['查询','重置'],
				yes : function(index,layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					searchParams = iframeWin.$("#searchForm").serialize();
					var newparam = iframeWin.$("#searchForm").serializeJSON();
					iframeWin.parentIframeName = window.name;
					$.extend(newparam,activityTable.queryParams);
					$('#activity_table').datagrid('load',newparam);
					layer.close(index);
				},
				btn2 : function(index, layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					iframeWin.parentIframeName = window.name;
					iframeWin.$("#searchForm").form("clear");
					return false;
				},
				area : [ '50%', '50%' ],
				content : rootpath + '/activity/toSearch.do?'+searchParams
			});
		}
		//添加打开窗体
		function addactivity(BUSINESS_ID) {
			$.uitools.showLoading();//打开处理中遮罩层
			$.ajax({
				cache : true,
				type : "POST",
				url : rootpath + '/activity/findbyid.do',
				data : {
					BUSINESS_ID : BUSINESS_ID
				},
				error : function(request) {
					$.uitools.hideLoading();//关闭处理中遮罩层
					layer.msg('系统异常！', {
						icon : 2,
						time : 1000
					})
				},
				success : function(data) {
					$.uitools.hideLoading();//关闭处理中遮罩层
					if (data.success){
						parent.layer.open({
							title : '新增',
							type : 2,
							btn : [ '保存', '关闭' ],
							yes : function(index, layero) {
								var iframeWin =parent.window[layero.find('iframe')[0]['name']];
								iframeWin.parentIframeName = window.name;
								iframeWin.$("#activityForm").submit();
							},
							btn2 : function(index, layero) {
							},
							area : [ '90%', '90%' ],
							content : rootpath + '/activity/toAdd.do?BUSINESS_ID=' + BUSINESS_ID
						});
					}else {
						layer.msg('只能有一个有效活动！', {
							icon : 2,
							time : 1000
						})
					}
				}
			});
		}
		
		//添加打开窗体
		function able(BUSINESS_ID,ACTIVITY_ID) {
			$.uitools.showLoading();//打开处理中遮罩层
			$.ajax({
				cache : true,
				type : "POST",
				url : rootpath + '/activity/findbyid.do',
				data : {
					BUSINESS_ID : BUSINESS_ID
				},
				error : function(request) {
					$.uitools.hideLoading();//关闭处理中遮罩层
					layer.msg('系统异常！', {
						icon : 2,
						time : 1000
					})
				},
				success : function(data) {
					$.uitools.hideLoading();//关闭处理中遮罩层
					if (data.success){
						
						$.uitools.showLoading();//打开处理中遮罩层
						$.ajax({
							cache : true,
							type : "POST",
							url : rootpath + '/activity/delete.do',
							data : {
								ACTIVITY_ID : ACTIVITY_ID,
								DISABLE:'否'
							},
							error : function(request) {
								$.uitools.hideLoading();//关闭处理中遮罩层
								layer.msg('系统异常！', {
									icon : 2,
									time : 1000
								})
							},
							success : function(data) {
								$.uitools.hideLoading();//关闭处理中遮罩层
								if (data.success){
									window.activityTable.datagrid('reload');
									
								}else {
									layer.msg('请检查网络！', {
										icon : 2,
										time : 1000
									})
								}
							}
						});
						
						
						
					}else {
						layer.msg('只能有一个有效活动！', {
							icon : 2,
							time : 1000
						})
					}
				}
			});
		}
		//添加打开窗体
		function enable(ACTIVITY_ID) {
			
						
						$.uitools.showLoading();//打开处理中遮罩层
						$.ajax({
							cache : true,
							type : "POST",
							url : rootpath + '/activity/delete.do',
							data : {
								ACTIVITY_ID : ACTIVITY_ID,
								DISABLE:'是'
							},
							error : function(request) {
								$.uitools.hideLoading();//关闭处理中遮罩层
								layer.msg('系统异常！', {
									icon : 2,
									time : 1000
								})
							},
							success : function(data) {
								$.uitools.hideLoading();//关闭处理中遮罩层
								if (data.success){
									window.activityTable.datagrid('reload');
									
								}else {
									layer.msg('只能有一个有效活动！', {
										icon : 2,
										time : 1000
									})
								}
							}
						});
		
		}
		//编辑打开窗体
		function openedit(ACTIVITY_ID){
			parent.layer.open({
				title : '修改',
				type : 2,
				btn : ['保存','关闭'],
				yes : function(index,layero) {
					var iframeWin = parent.window[layero.find('iframe')[0]['name']];
					iframeWin.parentIframeName = window.name;
					iframeWin.$("#activityForm").submit();
				},
				btn2 : function(index, layero) {
				},
				area : [ '90%', '90%' ],
				content : rootpath + '/activity/toEdit.do?ACTIVITY_ID='+ACTIVITY_ID
			});
		}
		//删除
		function del() {
			var node = activityTable.datagrid('getSelected');
			if (node) {
				layer.confirm('您确定要删除吗？', {
					btn : [ '确定', '取消' ]
				}, function(index, layero) {
				    layer.close(index);
					$.uitools.showLoading();//打开处理中遮罩层
					$.ajax({
						cache : true,
						type : "POST",
						url : rootpath + '/activity/delete.do',
						data : {
							ACTIVITY_ID : node.ACTIVITY_ID
						},
						error : function(request) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							layer.msg('系统异常！', {
								icon : 2,
								time : 1000
							})
						},
						success : function(data) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							if (data.success){
								layer.msg('删除成功！', {
									icon : 1,
									time : 1000
								}, function() {
									activityTable.datagrid('reload');
								})
							}else {
								layer.msg('删除异常！', {
									icon : 2,
									time : 1000
								})
							}
						}
					});
				}, function() {
				});
			} else {
				layer.msg('请选择一条数据！', {
					time : 1000
				})
			}
		}